package com.huisou.indexhelp;

import java.util.ArrayList;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.response.UpdateResponse;

import com.huisou.solrj.SolrServerUtil;

public class DeleteIndex {
	
	public static UpdateResponse deleteById(ArrayList<String> ids, String solrcore) {
		try {
			SolrServer server = SolrServerUtil.getSolrServer(solrcore);
			UpdateResponse res = server.deleteById(ids);
			server.commit();
			System.out.println(res.getResponse());
			return res;
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static UpdateResponse deleteById(String id, String solrcore) {
		try {
			SolrServer server = SolrServerUtil.getSolrServer(solrcore);
			UpdateResponse res = server.deleteById(id);
			server.commit();
			return res;
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static UpdateResponse deleteByQuery(String query, String solrcore) {
		try {
			SolrServer server = SolrServerUtil.getSolrServer(solrcore);
			UpdateResponse res = server.deleteByQuery(query);
			server.commit();
			return res;
		}
		catch (Exception e) {
			return null;
		}
	}
	

	public static void main(String[] args) throws Exception {
		String solrcore = "sale";
		// ArrayList<String> ids = new ArrayList<String>();
		//deleteById("1776897", solrcore);
		String query = "title:长治筋";
		deleteByQuery(query, solrcore);
	}
}
